Title: SQL BT (By-BKK) / 07 Joins
Tags: Obsidian_to_Anki

Q: What is the purpose of an OUTER JOIN in SQL?
A: To include data from one or both tables even if there's no match in the other

Q: What are the three main types of OUTER JOINs?
A: LEFT JOIN, RIGHT JOIN, FULL JOIN

Q: True or False: INNER JOIN only includes rows with matching keys in both tables.
A: True

Q: How does a LEFT JOIN work in SQL?
A: Includes all rows from the left table and matched rows from the right table

Q: How does a RIGHT JOIN work in SQL?
A: Includes all rows from the right table and matched rows from the left table

Q: What does a FULL JOIN do in SQL?
A: Includes all rows from both tables, matched or not

Q: What keyword specifies the join column in OUTER JOINs?
A: ON

Q: Is "OUTER" required after LEFT, RIGHT, or FULL for these joins?
A: No, it's optional and for compatibility

Q: What must you handle in results when using OUTER JOINs?
A: NULL values for unmatched rows

Q: Reverse card: To include unmatched rows from one or both tables in results
A: Why would you use an OUTER JOIN instead of an INNER JOIN?

Q: Reverse card: LEFT JOIN, RIGHT JOIN, FULL JOIN
A: Name the three main OUTER JOIN types in SQL

Q: Reverse card: True
A: Does INNER JOIN only include rows present in both tables?

Q: Reverse card: Includes all rows from the left table and matched rows from the right
A: How does a LEFT JOIN operate in SQL?

Q: Reverse card: Includes all rows from both tables, matched or not
A: What does a FULL JOIN do in SQL?

Q: Reverse card: NULL values for unmatched rows
A: What extra issue must you handle when using OUTER JOINs?

Q: Write an example LEFT JOIN to get buildings and their employees.
A: SELECT * FROM buildings LEFT JOIN employees ON buildings.name = employees.building

Q: How do you list all buildings and their capacity?
A: SELECT building_name, capacity FROM buildings

Q: Which query shows distinct employee roles in each building, including empty buildings?
A: SELECT building_name, role FROM buildings LEFT JOIN employees ON buildings.name = employees.building